﻿namespace My.Hydrator.Formatters
{
    using System;
    using System.ComponentModel.DataAnnotations;
    using My.Hydrator.Helpers;

    public class NumericDataTypeFormatter<TType> : BaseDataTypeFormatter, IDataTypeFormatter
    {
        private readonly string customDataType;

        private readonly TType minValue;

        private readonly TType maxValue;

        public NumericDataTypeFormatter(TType minValue, TType maxValue, string customDataType)
        {
            if (string.IsNullOrEmpty(customDataType))
            {
                throw new ArgumentException();
            }

            this.customDataType = customDataType;
            this.minValue = minValue;
            this.maxValue = maxValue;
        }

        public virtual DataTypeAttribute FormatterDataType
        {
            get { return new DataTypeAttribute(this.customDataType); }
        }

        public virtual object GetFormat()
        {
            return this.Random.Next<TType>(this.minValue, this.maxValue);
        }
    }
}
